package com.libbase.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.libbase.R;
import com.libbase.bean.NyqfBean;
import com.libbase.glide.GlideUtil;

import java.util.ArrayList;


public class NyqfNewAdapter extends BaseMultiItemQuickAdapter<NyqfBean.NewBean, BaseViewHolder> {

    public static final int ITEM_TEXT = 1;
    public static final int ITEM_IMG = 2;
    public static final int ITEM_VIDEO = 3;

    public NyqfNewAdapter() {
        super(new ArrayList<NyqfBean.NewBean>());
        addItemType(ITEM_TEXT, R.layout.item_nyqf_text);
        addItemType(ITEM_IMG, R.layout.item_nyqf_img);
        addItemType(ITEM_VIDEO, R.layout.item_nyqf_video);
        setDefaultViewTypeLayout(R.layout.item_nyqf_text);
    }

    @Override
    protected void convert(final BaseViewHolder helper, NyqfBean.NewBean item) {
        helper.setText(R.id.tv_item_nyqf_title, item.getTitle());
        helper.setText(R.id.tv_item_nyqf_time, item.getTime());
        if (item.getItemType() == ITEM_IMG) {
            GlideUtil.loadImage((ImageView) helper.getView(R.id.iv_item_nyqf_img), item.getPoster());
        } else if (item.getItemType() == ITEM_VIDEO) {
            GlideUtil.loadImage((ImageView) helper.getView(R.id.iv_item_nyqf_videoimg), getMp4Img(item.getPoster()));
            helper.addOnClickListener(R.id.fl_item_nyqf_video);
        }
        helper.addOnClickListener(R.id.ll_item_nyqf);
    }

    private String getMp4Img(String path) {
        int end = path.lastIndexOf("/");
        path = path.substring(end + 1);
        end = path.lastIndexOf(".");
        path = path.substring(0, end);
        return "http://yxb.southtv.cn:9180/temp/" + path + ".jpg";
    }
}
